package com.mallcai.bigdata.ladon.vo.system;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前端菜单
 * Created by oneape<oneape15@163.com>
 * Created 2019-06-24 17:16.
 * Modify:
 */
@Data
@NoArgsConstructor
public class MenuVo implements Serializable {
    private String path;
    private String name;
    private String icon;
    private String redirect;

    private Map<String, String> props = new HashMap<>(); // 节点额外属性值
    private Boolean             exact = true;
    private List<MenuVo> children;

    public MenuVo(String path) {
        this.path = path;
    }

    public MenuVo(String path, String name) {
        this.path = path;
        this.name = name;
    }

    public MenuVo(String path, String name, String icon) {
        this.path = path;
        this.name = name;
        this.icon = icon;
    }

    public MenuVo(String path, String name, String icon, List<MenuVo> children) {
        this.path = path;
        this.name = name;
        this.icon = icon;
        this.children = children;
    }

    public MenuVo addChild(MenuVo menu) {
        if (menu == null) {
            return this;
        }

        if (children == null) {
            children = new ArrayList<>();
        }
        children.add(menu);
        return this;
    }

    public void addProp(String key, String value) {
        if (StringUtils.isBlank(key)) {
            return;
        }
        props.put(key, value);
    }

    public String getProp(String key) {
        if (StringUtils.isBlank(key)) {
            return null;
        }

        return props.get(key);
    }

    public void addChildren(List<MenuVo> tmp) {
        if (tmp == null) {
            return;
        }

        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        children.addAll(tmp);
    }

}
